package com.pignest.hotel.module.user.ui;

import java.util.List;

import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listhead;
import org.zkoss.zul.Listheader;
import org.zkoss.zul.Listitem;

import com.pignest.hotel.beans.Member;
import com.pignest.hotel.beans.MemberPrice;
import com.pignest.hotel.service.MemberService;
import com.pignest.hotel.spring.Services;
import com.pignest.hotel.util.MoneyUtil;
import com.pignest.hotel.util.WhereCreator;

public class MemberPriceListbox extends Listbox {
	
	private MemberService memberService;
	
	private String queryLevelId;
	
	private String queryRoomTypeId;
	
	public MemberPriceListbox(){
		memberService=Services.getMemberService();
	}
	public void onCreate() {
		//this.setHead();
		Query(null,null);
	}
	public void Query(String roomtype,String memberLevel){
		this.getItems().clear();
		StringBuffer hql=new StringBuffer();
		WhereCreator where =new WhereCreator();
		hql.append(" from MemberPrice b where 1=1 ");
		if(roomtype!=null&&!roomtype.equals("")){
			hql.append(" and b.roomType.id= '"+roomtype+"'");
		}
		if(memberLevel!=null&&!memberLevel.equals("")){
			hql.append(" and b.memberLevel.id = '"+memberLevel+"'");
		}
		List<MemberPrice> memberPrices=memberService.findMemberPrice(hql.toString());
		for(int i=0;i<memberPrices.size();i++){
			MemberPrice memberPrice= memberPrices.get(i);
			Listitem listitem = new Listitem();
			listitem.setValue(memberPrice.getId());
			listitem.setParent(this);
			listitem.appendChild(new Listcell(Integer.toString(i+1)));
			listitem.appendChild(new Listcell(memberPrice.getMemberLevel().getMemberlevel()));
			listitem.appendChild(new Listcell(memberPrice.getRoomType().getName()));
			listitem.appendChild(new Listcell(MoneyUtil.toString(memberPrice.getPrice())));
			
		}
	}

	public String getQueryLevelId() {
		return queryLevelId;
	}
	public void setQueryLevelId(Listbox levelListbox) {
		String levelId=(String)levelListbox.getSelectedItem().getAttribute("value");
		this.queryLevelId = levelId;
	}
	public String getQueryRoomTypeId() {
		return queryRoomTypeId;
	}
	public void setQueryRoomTypeId(Listbox roomtypeListbox) {
		String roomtypeId=(String)roomtypeListbox.getSelectedItem().getAttribute("value");
		this.queryRoomTypeId = roomtypeId;
	}
	public void queryPrice(){
		System.out.println("this.queryRoomTypeId:"+this.queryRoomTypeId+";this.queryLevelId:"+this.queryLevelId);
		Query(this.queryRoomTypeId,this.queryLevelId);
	}

}
